package com.eudon.design_pattern.behavioral.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author eudon
 * @description 策略工厂，创建所有策略
 * @date 2025/9/2
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class StrategyFactory {
    private static final Map<String, Strategy> STRATEGY_MAP = new HashMap<>();
    static {
        STRATEGY_MAP.put("A", new StrategyA());
        STRATEGY_MAP.put("B", new StrategyB());
        STRATEGY_MAP.put("C", new StrategyC());
        //...
    }

    public static Strategy getInstance(String type) {
        Strategy strategy = STRATEGY_MAP.get(type);
        if (strategy == null) {
            //默认采用策略A
            return STRATEGY_MAP.get("A");
        }
        return strategy;
    }
}
